﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using AForge.Math;
using AForge.Imaging;
using System.Drawing.Imaging;
using AForge.Imaging.Filters;

namespace Pikamay
{
    public partial class Form1 : Form
    {
        private Bitmap img;
        private List<Bitmap> listimg = new List<Bitmap>();

        public Form1()
        {
            InitializeComponent();
            this.Paint += Form1_Paint;
            img = (Bitmap)System.Drawing.Image.FromFile("J:\\pikamay.jpg");
        }

        void Form1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.DrawImage(img, 0, 0, 504, 360);
            if (listimg.Count != 0)
            {
                for (int i = 0; i < listimg.Count; i++)
                {
                    e.Graphics.DrawImage(listimg[i], (i / 10) * 40 , (i%10)*40 + 370, 36, 36);
                }
            }

        }
           
            

        private void button1_Click(object sender, EventArgs e)
        {
            Bitmap temp = img.Clone() as Bitmap;

            FiltersSequence seq = new FiltersSequence();
            seq.Add(Grayscale.CommonAlgorithms.RMY);  //First add  GrayScaling filter
            //seq.Add(new Threshold(150)); //Then add binarization(thresholding) filter

            temp = seq.Apply(img);

            for (int i = 0; i < 14; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    Rectangle rect = new Rectangle(i * 36, j * 36, 36, 36);
                    Bitmap tmp = temp.Clone(rect, PixelFormat.DontCare);
                    listimg.Add(tmp);
                }
                
            }
            this.Refresh();
        }
    }
}
